const express= require('express')
const router=express.Router()

//导入各个路由对应的api
const login=require('../api/login')
const users=require('../api/users')
const rights=require('../api/rights')
const organization=require('../api/organization')
const roles=require('../api/roles')

//导入验证表单数据的中间件
const expressJoi=require('@escook/express-joi')
//导入我们需要验证规则的对象
const {login_schema,update_users} =require('../schema/user')



/*===登录模块===*/
router.post('/login',expressJoi(login_schema),login.login)  //再进行登录逻辑前进行中间件表单数据验证
router.post('/getloginUser',login.getloginUser)  //获取登录上的用户的资料
 


/*===用户信息模块===*/
router.get('/users',users.getusers)
router.get('/users/:id',users.getusersByid)
router.post('/users',expressJoi(update_users),users.addusers)
router.delete('/users/:id',users.removeuser)
router.put('/users/:id',users.updatausers)//,expressJoi(update_users)
router.put('/users',users.editUsersPasswor)

/*======组织结构======*/

router.get('/organization',organization.getOrganization)
router.post('/organization',organization.addOrganization)
router.delete('/organization/:id',organization.removeOrganization)
router.put('/organization/:id',organization.editOriganization)


/*========角色模块======*/

router.get('/roles',roles.getroles)
router.get('/getrolesByUserId/:id',roles.getrolesByUserId)
router.post('/roles',roles.addroles)
router.delete('/roles/:id',roles.removeroles)
router.get('/roles/:id',roles.getDetaileRoles)
router.put('/roles/:id',roles.updateRoles)
router.put('/roles',roles.assignPrem)
router.put('/setUserRoles',roles.setUserRoles)


/*========权限模块======*/
router.get('/rights',rights.getrights)
router.post('/rights',rights.addrights)
router.delete('/rights/:id',rights.removerights)
router.get('/rights/:id',rights.getdetail)
router.put('/rights',rights.updaterights)






module.exports=router